//
// Created by 32827 on 2024/2/11.
//
#include "user_view_control.hpp"
ViewControl::ViewControl(YZL_VIEW *viewRam): ViewBase(viewRam) {
    mLayoutVertical = new LayoutVertical(this);
    mLayoutVertical->setRange(10,10,240,450,15);
    mLayoutVertical->setMargin(5);
}
//------------------------------------------------------------------
extern "C" void user_pp_ui_delTopView();
extern "C" void addDialog(utf8* text);
void del_self_listener(void *widget, YZL_UI_CTR_EVENT event){
    if(event==YZL_UI_CTR_EVENT_TOUCH_UP){
        user_pp_ui_delTopView();
    }
}
void mpu6050_init_listener(void *widget, YZL_UI_CTR_EVENT event){
    if(event==YZL_UI_CTR_EVENT_TOUCH_UP){
        yzf_area_recv_add(yz_recv_transmit_area_get(),0x07);
        yzf_area_recv_add(yz_recv_transmit_area_get(),0x00);
        yzf_area_recv_add(yz_recv_transmit_area_get(),0x00);
        yzf_area_recv_add(yz_recv_transmit_area_get(),0x00);
    }
}
//------------------------------------------------------------------
YZF_BOOL ViewControl::initP(void *initStructPointer, void *actStructPointer){
    ViewBase::initP(initStructPointer, actStructPointer);

    mMPU6050Button=new WidgetButton((*this)[-1],mLayoutVertical->nextRect(), 0,(utf8 *) "初始化MPU6050");
    mMPU6050Button->setListener(mpu6050_init_listener);
    addChild(mMPU6050Button);

    mExactControl=new WidgetProgressTouch((*this)[-1],mLayoutVertical->nextRect(), 0,BLACK,RED,2,100,50);
    addChild(mExactControl);

    mExitButton=new WidgetButton((*this)[-1],mLayoutVertical->nextRect(), 0,(utf8 *) "退出");
    mExitButton->setListener(del_self_listener);
    addChild(mExitButton);
    return YZF_TRUE;
}

YZF_BOOL ViewControl::deInitP() {
    return ViewBase::deInitP();
}

char *ViewControl::getViewName() {
    return "ViewControl";
}

int ViewControl::getViewId() {
    return 2;
}

ViewControl::~ViewControl(){
    delete mLayoutVertical;
}
void ViewControl::wakeupP(void *actStructPointer) {
    yzl_ui_draw_565a("/MMC/background.565a",0,0);
    yzl_ui_draw_rect(10,10,240,450,YZF_FALSE,WHITE);
    ViewBase::wakeupP(actStructPointer);
}
